package fr.syntheses.blog.Model.DAO;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.apache.log4j.Logger;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;

import fr.syntheses.blog.beans.Categorie;

public class CategorieDAOH extends ModeleDAO {

	private Logger log = Logger.getLogger(currentClassToLog);
	
	private List<Categorie> listeCategorie;
	
    // retourner la liste des clients
	public List<Categorie> getListeCategorie() {	
		// Variables
		listeCategorie = new ArrayList<Categorie>();
		Session session = null;
		Query query = null;
		
		try {
		//HibernateUtil.createSessionFactory();
		
		session = HibernateUtil.getSession();
		
		try {
			query = session.createQuery("from Categorie");
			Iterator categories = query.iterate();
			
			while (categories.hasNext()) {
				listeCategorie.add((Categorie) categories.next());
			}
		} finally {
			//session.close();
		}
		} catch (HibernateException e) {
			log.fatal("/* ATTENTION GRAVE ERREUR LORS DE LA CREATION DE LA SESSION FACTORY HB */");
			log.fatal(e);
		} finally {
		//	HibernateUtil.closeSessionFactory();
		}
		return listeCategorie;
	}
	
	public void create() {
		throw new UnsupportedOperationException();
	}

	public void read() {
		throw new UnsupportedOperationException();
	}

	public void update() {
		throw new UnsupportedOperationException();
	}

	public void delete() {
		throw new UnsupportedOperationException();
	}
}